package com.twu.biblioteca;

/**
 * Created by sravanns on 19/06/14.
 */
public class LoginAsLibrarian implements Login {
    Library library;
    UIApplication uiApplication;
    public LoginAsLibrarian(Library library, UIApplication uiApplication) {
        this.library=library;
        this.uiApplication=uiApplication;
    }

    @Override
    public String toString() {
        return "Login as Librarian";
    }

    @Override
    public ResultLogin performAction() throws InterruptedException {

        ResultLogin resultLogin=new ResultLogin();
        Result result=new Result();

        uiApplication.display("Enter librarian id");
        String username=uiApplication.acceptUserName();
        uiApplication.display("enter passwoed");
        String password=uiApplication.acceptPassword();
        if(username.equals("librarian") && password.equals("thoughtworks"))
        {
            result.setResult("Logged in as Librarian",true);
            resultLogin.setResultLogin("librarian", result);
        }
        else {
            result.setResult("Invalid credentials", false);
            resultLogin.setResultLogin("librarian", result);
        }
        return resultLogin;
    }
}
